import 'package:badges/badges.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:mxapp/utils/global.dart';

class MyDemo01 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
//          backgroundColor: Colors.white10,
          centerTitle: false,
          elevation: 0,
          actions: <Widget>[
            IconButton(
                icon: Icon(shezhi1), color: Colors.white, onPressed: () {}),
            IconButton(
                icon: Icon(yifu), color: Colors.white, onPressed: () {}),
            SizedBox(
              width: 7,
            )
          ],
        ),
        body: MyDemo(),
        floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
        floatingActionButton: FloatingActionButton(
          elevation: 0,
          backgroundColor: Colors.black26,
          onPressed: () => print("FloatingActionButton"),
          child: Icon(Icons.add,color: Colors.deepOrange,size: 35,),
          heroTag: null,
        ),
      );
  }
}

class MyDemo extends StatefulWidget {
  @override
  _MyDemoState createState() => _MyDemoState();
}

class _MyDemoState extends State<MyDemo> {
  @override
  Widget build(BuildContext context) {
    return SafeArea(
        child: ListView(
          physics: BouncingScrollPhysics(),
      padding: EdgeInsets.all(12),
      children: <Widget>[
        Padding(padding: EdgeInsets.only(bottom: 15),
          child: Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                ClipOval(
                  child: Image.network(
                    "http://f.hiphotos.baidu.com/zhidao/pic/item/ac345982b2b7d0a2a14af2cbcbef76094a369ae1.jpg",
                    width: 55,
                  ),
                ),
                SizedBox(
                  width: 15,
                ),
                Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Row(
                      children: <Widget>[
                        Text(
                          '花间草',
                          style: TextStyle(
                              fontSize: 20, fontWeight: FontWeight.bold),
                        )
                      ],
                    ),
                    SizedBox(
                      height: 5,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: <Widget>[
                        TitleGrade(
                          num: 102,
                          icon: Icons.grade,
                        ),
                        TitleGrade(
                          num: 121,
                          icon: Icons.share,
                        ),
                        TitleGrade(
                          num: 58,
                          icon: Icons.query_builder,
                        ),
                      ],
                    ),
                  ],
                ),
              ],
            ),
            Container(
                alignment: Alignment.center,
                width: 70,
                height: 28,
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(50),
                    color: Colors.deepOrangeAccent),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisSize: MainAxisSize.min,
                  children: <Widget>[
                    Icon(
                      Icons.check_circle_outline,
                      color: Colors.white,
                      size: 20,
                    ),
                    SizedBox(
                      width: 2,
                    ),
                    Text(
                      '签到',
                      style: TextStyle(
                          color: Colors.white,
                          fontSize: 12,
                          fontWeight: FontWeight.w200),
                    ),
                  ],
                ))
          ],
        ),),
        Divider(
          color: Colors.black12,
        ),
        Row(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            ItemizeGrade(
              title: '消息',
              icon: xiaoxi2,
              num: 90,
            ),
            ItemizeGrade(
              title: '我的任务',
              icon: renwu3,
            ),
            ItemizeGrade(
              title: '斗鱼贵族',
              icon: guizu,
            ),
            ItemizeGrade(
              title: '鱼翅充值',
              icon: chongzhi,
              num: 14,
            ),
          ],
        ),
        Padding(
          padding: EdgeInsets.only(top: 15),
          child: Card(
            shape: const RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(12.0))),
            elevation: 0,
            child: ListBody(
              mainAxis: Axis.vertical,
              children: <Widget>[
                CategoryLevelFront(
                  icon: Icons.color_lens,
                  color: Colors.red,
                  title: '我的等级',
                  level: 'Lv2',
                ),
                CategoryLevelFront(
                  icon: Icons.person_pin,
                  color: Colors.deepOrangeAccent,
                  title: '我的空间',
                ),
                CategoryLevelFront(
                  icon: Icons.spa,
                  color: Colors.lightGreen,
                  title: '免流量特权',
                ),
                CategoryLevelFront(
                  icon: Icons.event_note,
                  color: Colors.blueAccent,
                  title: '主播小说',
                ),
              ],
            ),
          ),
        ),
        Padding(
          padding: EdgeInsets.only(top: 15),
          child: Card(
            shape: const RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(12.0))),
            elevation: 0,
            child: ListBody(
              mainAxis: Axis.vertical,
              children: <Widget>[
                CategoryLevelFront(
                  icon: Icons.school,
                  color: Colors.blue,
                  title: '我的头衔',
                ),
                CategoryLevelFront(
                  icon: Icons.all_inclusive,
                  color: Colors.green,
                  title: '我的粉丝徽章',
                ),
              ],
            ),
          ),
        ),
        Padding(
          padding: EdgeInsets.only(top: 15),
          child: Card(
            shape: const RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(12.0))),
            elevation: 0,
            child: ListBody(
              mainAxis: Axis.vertical,
              children: <Widget>[
                CategoryLevelFront(
                  icon: Icons.local_play,
                  color: Colors.red,
                  title: '陪玩大厅',
                ),
                CategoryLevelFront(
                  icon: Icons.games,
                  color: Colors.deepPurple,
                  title: '我的游戏',
                  level: '玩游戏领鱼丸',
                ),
                CategoryLevelFront(
                  icon: Icons.phone,
                  color: Colors.amberAccent,
                  title: '联系方式',
                ),
              ],
            ),
          ),
        ),
        Padding(
          padding: EdgeInsets.only(top: 15),
          child: Card(
            shape: const RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(12.0))),
            elevation: 0,
            child: ListBody(
              mainAxis: Axis.vertical,
              children: <Widget>[
                CategoryLevelFront(
                  icon: Icons.card_travel,
                  color: Colors.redAccent,
                  title: '我的钱包',
                ),
                CategoryLevelFront(
                  icon: Icons.monetization_on,
                  color: Colors.amber,
                  title: '兑换中心',
                ),
                CategoryLevelFront(
                  icon: Icons.phone,
                  color: Colors.black87,
                  title: '联系方式',
                ),
              ],
            ),
          ),
        ),
      ],
    )
    );
  }
}

// ignore: must_be_immutable
class CategoryLevelFront extends StatelessWidget {
  String title;
  IconData icon;
  Color color;
  String level;

  CategoryLevelFront({Key key, this.icon, this.title, this.color, this.level})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ListTile(
      title: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Icon(
            icon,
            size: 24,
            color: color == null ? Colors.black45 : color,
          ),
          SizedBox(
            width: 12,
          ),
          Text(
            title,
            style: TextStyle(
                fontSize: 14, fontWeight: FontWeight.w300, color: Colors.black),
          )
        ],
      ),
      contentPadding: EdgeInsets.only(left: 12, right: 12, top: 0, bottom: 0),
      trailing: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Text(
            level == null ? '' : level,
            style: TextStyle(color: Colors.black38),
          ),
          Icon(Icons.keyboard_arrow_right)
        ],
      ),
      onTap: () {
        print('我被点击了！！！');
      },
    );
  }
}

class TitleGrade extends StatelessWidget {
  int num;
  IconData icon;

  TitleGrade({Key key, this.icon, this.num}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Row(
        children: <Widget>[
          Icon(
            icon,
            color: Colors.black45,
            size: 14,
          ),
          Text(
            '$num',
            style: TextStyle(color: Colors.black26, fontSize: 12),
          ),
          SizedBox(
            width: 10,
          )
        ],
      ),
    );
  }
}

class ItemizeGrade extends StatelessWidget {
  String title;
  IconData icon;
  int num;

  ItemizeGrade({Key key, this.icon, this.title,this.num=0}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.all(10),
      child: Column(
        children: <Widget>[
          Badge(
            badgeColor: (num>1)?Colors.deepOrangeAccent:Colors.red,
            padding: EdgeInsets.all((num>1)?3:5),
            position:BadgePosition.bottomRight(bottom: (num>1)?18:20,right: -12),
            badgeContent: (num>1)?Text('$num',style: TextStyle(
              color: Colors.white,fontSize: 10
            ),):Container(
              height: num>10?num>100?3:num>1000?4:2:0,
              width: num>10?num>100?3:num>1000?4:2:0,
            ),
            child: Icon(
              icon,
              color: Colors.black,
              size: 30,
            ),
          ),
          SizedBox(
            height: 7,
          ),
          Text(
            title,
            style: TextStyle(
                color: Colors.black45,
                fontWeight: FontWeight.w400,
                fontSize: 12),
          )
        ],
      ),
    );
  }
}
